{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "- 一、简单爬取"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "import requests"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [],
   "source": [
    "url = 'https://www.baidu.com/'\n",
    "response = requests.get(url)\n",
    "response.encoding = 'utf-8'\n",
    "page_text = response.text\n",
    "with open('one.html', 'w', encoding='utf-8')as f:\n",
    "    f.write(page_text)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    " - 二、简易的网页采集器"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "https://www.baidu.com/wd=rmb\n",
    "https://www.sogou.com/web\n",
    "    \n",
    "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.108 Safari/537.36\n",
    "\n",
    "wd: rmb"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 百度\n",
    "url = 'https://www.baidu.com/s'\n",
    "headers = {\n",
    "    'User-Agent':'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.108 Safari/537.36'\n",
    "}\n",
    "param = {\n",
    "    'wd': 'zfy'\n",
    "}\n",
    "response = requests.get(url, params=param, headers=headers)\n",
    "response.encoding = 'utf-8'\n",
    "page_text = response.text\n",
    "with open('zfy1.html', 'w', encoding='utf-8')as f:\n",
    "    f.write(page_text)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "请输入你想查询的东西：周道镕\n"
     ]
    }
   ],
   "source": [
    "# 搜狗\n",
    "url = 'https://www.sogou.com/web'\n",
    "headers = {\n",
    "    'User-Agent':'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.108 Safari/537.36'\n",
    "}\n",
    "wd = input('请输入你想查询的东西：')\n",
    "param = {\n",
    "    'query': wd\n",
    "}\n",
    "response = requests.get(url, params=param, headers=headers)\n",
    "response.encoding = 'utf-8'\n",
    "page_text = response.text\n",
    "with open(wd + '.html', 'w', encoding='utf-8')as f:\n",
    "    f.write(page_text)\n",
    "print('搜索成功！')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "- 三、爬去自动分页中的ajax请求"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "https://movie.douban.com/j/chart/top_list  ajax请求页面\n",
    "    在页面中"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "完成！\n"
     ]
    }
   ],
   "source": [
    "url = 'https://movie.douban.com/j/chart/top_list'\n",
    "with open('movies.txt', 'w', encoding='utf-8')as f:\n",
    "    for i in range(0,11):\n",
    "        headers = {\n",
    "            'User-Agent':'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.108 Safari/537.36'\n",
    "        }\n",
    "        param = {\n",
    "            'type': '26',\n",
    "            'interval_id': '100:90',\n",
    "            'action': '',\n",
    "            'start': str(i*20),\n",
    "            'limit': '20',\n",
    "        }\n",
    "        response = requests.get(url=url, params=param, headers=headers)\n",
    "        response.encoding = 'utf-8'\n",
    "        page_data = response.json()\n",
    "        for i in page_data:\n",
    "            # print(page_data)\n",
    "            # print(i['title'])\n",
    "            if float(i['rating'][0]) > 9: \n",
    "                f.write(i['title']+ i['rating'][0] + '\\n')\n",
    "print('完成！')\n",
    "\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "- 四、动态加载数据\n",
    "获取页面的展示数据"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "http://www.kfc.com.cn/kfccda/ashx/GetStoreList.ashx"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 37,
   "metadata": {
    "collapsed": true
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "育慧里\n",
      "京通新城\n",
      "黄寺大街\n",
      "四季青桥\n",
      "亦庄\n",
      "石园南大街\n",
      "北京站广场\n",
      "北京南站\n",
      "北清路\n",
      "大红门新世纪肯德基餐厅\n"
     ]
    }
   ],
   "source": [
    "url = 'http://www.kfc.com.cn/kfccda/ashx/GetStoreList.ashx?op=keyword'\n",
    "headers = {\n",
    "            'User-Agent':'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.108 Safari/537.36'\n",
    "        }\n",
    "data = {\n",
    "    'cname': '',\n",
    "    'pid': '',\n",
    "    'keyword': '北京',\n",
    "    'pageIndex': '1',\n",
    "    'pageSize': '10',\n",
    "}\n",
    "\n",
    "response = requests.post(url=url, headers=headers, data=data)\n",
    "response.encoding = 'utf-8'\n",
    "response_data = response.json()\n",
    "# response_data\n",
    "for i in response_data['Table1']:\n",
    "    print(i['storeName'])"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "- 五、动态加载数据\n",
    "药监总局数据爬取，爬取的是每一家企业的详情数据"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "详细页面找到的：http://125.35.6.84:81/xk/itownet/portalAction.do?method=getXkzsById"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "首页中找到的：http://125.35.6.84:81/xk/itownet/portalAction.do?method=getXkzsList"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {
    "collapsed": true
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "成功！\n",
      "[{'businessLicenseNumber': '91341600MA2RHKJ548', 'businessPerson': '修海', 'certStr': '一般液态单元（啫喱类、护发清洁类、护肤水类）；膏霜乳液单元（护发类、护肤清洁类）；粉单元（块状粉类、散粉类、浴盐类）；蜡基单元（蜡基类）', 'cityCode': '', 'countyCode': '', 'creatUser': '', 'createTime': '', 'endTime': '', 'epsAddress': '安徽省亳州市谯城区三官工业街168号', 'epsName': '亳州嘉禾药业有限公司', 'epsProductAddress': '安徽省亳州市谯城区三官工业街168号', 'id': '', 'isimport': 'N', 'legalPerson': '修海', 'offDate': '', 'offReason': '', 'parentid': '', 'preid': '', 'processid': '20191127091203206def8z', 'productSn': '皖妆20190004', 'provinceCode': '', 'qfDate': '', 'qfManagerName': '安徽省药品监督管理局', 'qualityPerson': '楼倚天', 'rcManagerDepartName': '亳州市市场监督管理局', 'rcManagerUser': '夏雷、刘振伟', 'startTime': '', 'xkCompleteDate': None, 'xkDate': '2024-07-07', 'xkDateStr': '2019-11-29', 'xkName': '许红', 'xkProject': '', 'xkRemark': '', 'xkType': '206'}, {'businessLicenseNumber': '91440607MA53CU882Q', 'businessPerson': '白婷', 'certStr': '一般液态单元（护发清洁类、护肤水类、啫喱类）；膏霜乳液单元（护肤清洁类、护发类）', 'cityCode': '', 'countyCode': '', 'creatUser': '', 'createTime': '', 'endTime': '', 'epsAddress': '佛山市三水区乐平镇西乐大道东39号登骏数码城二期厂房B3号301A、401A、501A单元（住所申报）', 'epsName': '倍斯柔（广东）生物科技有限公司', 'epsProductAddress': '佛山市三水区乐平镇西乐大道东39号登骏数码城二期厂房B3号301A、401A、501A单元（住所申报）', 'id': '', 'isimport': 'Y', 'legalPerson': '白婷', 'offDate': '', 'offReason': '', 'parentid': '', 'preid': '', 'processid': '', 'productSn': '粤妆20190264', 'provinceCode': '', 'qfDate': '', 'qfManagerName': '广东省药品监督管理局', 'qualityPerson': '黄伯宁', 'rcManagerDepartName': '佛山市市场监督管理局 三水区市场监督管理局', 'rcManagerUser': '由日常监督机构指派', 'startTime': '', 'xkCompleteDate': None, 'xkDate': '2024-11-27', 'xkDateStr': '2019-11-28', 'xkName': '严振', 'xkProject': '', 'xkRemark': '无', 'xkType': '201'}, {'businessLicenseNumber': '91440605MA51UD1D9Q', 'businessPerson': '林明敏', 'certStr': '一般液态单元（护发清洁类）；膏霜乳液单元（护肤清洁类）', 'cityCode': '', 'countyCode': '', 'creatUser': '', 'createTime': '', 'endTime': '', 'epsAddress': '佛山市南海区丹灶镇塱心工业区吴伟升厂房自编A座1楼、2楼（住所申报）', 'epsName': '佛山市方方洁生物科技有限公司', 'epsProductAddress': '广东省佛山市南海区丹灶镇塱心工业区吴伟升厂房自编A座1楼、2楼（住所申报）', 'id': '', 'isimport': 'Y', 'legalPerson': '林明敏', 'offDate': '', 'offReason': '', 'parentid': '', 'preid': '', 'processid': '', 'productSn': '粤妆20190263', 'provinceCode': '', 'qfDate': '', 'qfManagerName': '广东省药品监督管理局', 'qualityPerson': '黄丽兰', 'rcManagerDepartName': '佛山市市场监督管理局 南海区市场监督管理局', 'rcManagerUser': '由日常监督机构指派', 'startTime': '', 'xkCompleteDate': None, 'xkDate': '2024-11-27', 'xkDateStr': '2019-11-28', 'xkName': '严振', 'xkProject': '', 'xkRemark': '无', 'xkType': '201'}, {'businessLicenseNumber': '91370285MA3M0AJB0Q', 'businessPerson': '孙滨', 'certStr': '一般液态单元（护发清洁类、护肤水类、染烫发类、啫喱类），膏霜乳液单元（护肤清洁类、护发类、染烫发类）', 'cityCode': '', 'countyCode': '', 'creatUser': '', 'createTime': '', 'endTime': '', 'epsAddress': '山东省青岛市莱西市夏格庄文昌路8号', 'epsName': '青岛尚合生物科技有限公司', 'epsProductAddress': '山东省青岛市莱西市夏格庄文昌路8号', 'id': '', 'isimport': 'Y', 'legalPerson': '王悦卉', 'offDate': '', 'offReason': '', 'parentid': '', 'preid': '', 'processid': '', 'productSn': '鲁妆20190010', 'provinceCode': '', 'qfDate': '', 'qfManagerName': '山东省食品药品监督管理局', 'qualityPerson': '周林丽', 'rcManagerDepartName': '莱西市市场监督管理局', 'rcManagerUser': '王庆平、王学良', 'startTime': '', 'xkCompleteDate': None, 'xkDate': '2024-11-27', 'xkDateStr': '2019-11-28', 'xkName': '史国生', 'xkProject': '', 'xkRemark': '无', 'xkType': '201'}, {'businessLicenseNumber': '91370611MA3P4QUY7W', 'businessPerson': '王宝仁', 'certStr': '一般液态单元（护肤水类）', 'cityCode': '', 'countyCode': '', 'creatUser': '', 'createTime': '', 'endTime': '', 'epsAddress': '山东省烟台市福山区振华街879号', 'epsName': '山东暨肽生物医药科技有限公司', 'epsProductAddress': '山东省烟台市福山区振华街879号', 'id': '', 'isimport': 'Y', 'legalPerson': '王宝仁', 'offDate': '', 'offReason': '', 'parentid': '', 'preid': '', 'processid': '', 'productSn': '鲁妆20190009', 'provinceCode': '', 'qfDate': '', 'qfManagerName': '山东省食品药品监督管理局', 'qualityPerson': '孙韵', 'rcManagerDepartName': '烟台市福山区市场监督管理局', 'rcManagerUser': '周旭生、车艳', 'startTime': '', 'xkCompleteDate': None, 'xkDate': '2024-11-27', 'xkDateStr': '2019-11-28', 'xkName': '史国生', 'xkProject': '', 'xkRemark': '无', 'xkType': '201'}, {'businessLicenseNumber': '91330127096533628U', 'businessPerson': '王巧琴', 'certStr': '粉单元（散粉类）； ', 'cityCode': '', 'countyCode': '', 'creatUser': '', 'createTime': '', 'endTime': '', 'epsAddress': '浙江省杭州市淳安县千岛湖镇永和路321号1幢2楼', 'epsName': '淳安千岛湖诚达实业有限公司', 'epsProductAddress': '浙江省杭州市淳安县千岛湖镇永和路321号1幢2楼', 'id': '', 'isimport': 'Y', 'legalPerson': '吴祖红', 'offDate': '', 'offReason': '', 'parentid': '', 'preid': '', 'processid': '', 'productSn': '浙妆20190061', 'provinceCode': '', 'qfDate': '', 'qfManagerName': '浙江省药品监督管理局', 'qualityPerson': '赵叶飞', 'rcManagerDepartName': '淳安县市场监督管理局', 'rcManagerUser': '李来胜，王洁', 'startTime': '', 'xkCompleteDate': None, 'xkDate': '2024-11-26', 'xkDateStr': '2019-11-27', 'xkName': '苏志良', 'xkProject': '', 'xkRemark': '', 'xkType': '201'}, {'businessLicenseNumber': '91330782MA2E66BQ55', 'businessPerson': '蒋新法', 'certStr': '蜡基单元（蜡基类）； ', 'cityCode': '', 'countyCode': '', 'creatUser': '', 'createTime': '', 'endTime': '', 'epsAddress': '浙江省金华市义乌市廿三里街道安商路37号', 'epsName': '浙江好妆化妆品有限公司', 'epsProductAddress': '浙江省金华市义乌市廿三里街道安商路37号', 'id': '', 'isimport': 'Y', 'legalPerson': '蒋益文', 'offDate': '', 'offReason': '', 'parentid': '', 'preid': '', 'processid': '', 'productSn': '浙妆20190060', 'provinceCode': '', 'qfDate': '', 'qfManagerName': '浙江省药品监督管理局', 'qualityPerson': '赵雅雅', 'rcManagerDepartName': '义乌市市场监督管理局', 'rcManagerUser': '戴蔚，华斌', 'startTime': '', 'xkCompleteDate': None, 'xkDate': '2024-11-26', 'xkDateStr': '2019-11-27', 'xkName': '苏志良', 'xkProject': '', 'xkRemark': '', 'xkType': '201'}, {'businessLicenseNumber': '91440101MA5CUTW2XB', 'businessPerson': '肖文芳', 'certStr': '一般液态单元（护发清洁类、护肤水类、啫喱类）；膏霜乳液单元（护肤清洁类、护发类）', 'cityCode': '', 'countyCode': '', 'creatUser': '', 'createTime': '', 'endTime': '', 'epsAddress': '广州市花都区花山镇启源大道6号4栋304房', 'epsName': '美尚美生物技术（广州）有限公司', 'epsProductAddress': '广州市花都区花山镇启源大道6号4栋304房', 'id': '', 'isimport': 'Y', 'legalPerson': '肖文芳', 'offDate': '', 'offReason': '', 'parentid': '', 'preid': '', 'processid': '', 'productSn': '粤妆20190265', 'provinceCode': '', 'qfDate': '', 'qfManagerName': '广东省药品监督管理局', 'qualityPerson': '严敏', 'rcManagerDepartName': '花都区局花山市场监管所', 'rcManagerUser': '监管机构指定人员', 'startTime': '', 'xkCompleteDate': None, 'xkDate': '2024-11-26', 'xkDateStr': '2019-11-27', 'xkName': '严振', 'xkProject': '', 'xkRemark': '无', 'xkType': '201'}, {'businessLicenseNumber': '91440101558362852L', 'businessPerson': '徐伟洪', 'certStr': '一般液态单元（护发清洁类、护肤水类、啫喱类）；膏霜乳液单元（护肤清洁类、护发类）', 'cityCode': '', 'countyCode': '', 'creatUser': '', 'createTime': '', 'endTime': '', 'epsAddress': '广州市花都区赤坭镇白坭经济社内', 'epsName': '广州市联盈日用化妆品有限公司', 'epsProductAddress': '广州市花都区赤坭镇白坭经济社内', 'id': '', 'isimport': 'Y', 'legalPerson': '何健恒', 'offDate': '', 'offReason': '', 'parentid': '', 'preid': '', 'processid': '', 'productSn': '粤妆20160999', 'provinceCode': '', 'qfDate': '', 'qfManagerName': '广东省药品监督管理局', 'qualityPerson': '郝军伟', 'rcManagerDepartName': '花都区局市场监管所', 'rcManagerUser': '监管机构指定人员', 'startTime': '', 'xkCompleteDate': None, 'xkDate': '2021-10-25', 'xkDateStr': '2019-11-27', 'xkName': '严振', 'xkProject': '', 'xkRemark': '无', 'xkType': '206'}, {'businessLicenseNumber': '91331000742019640K', 'businessPerson': '王小兵', 'certStr': '产址1：气雾剂及有机溶剂单元（气雾剂类）； ', 'cityCode': '', 'countyCode': '', 'creatUser': '', 'createTime': '', 'endTime': '', 'epsAddress': '浙江省台州市三门县海润街道工业大道5号', 'epsName': '浙江绿岛科技有限公司', 'epsProductAddress': '海润街道工业大道5号', 'id': '', 'isimport': 'Y', 'legalPerson': '潘伊莉', 'offDate': '', 'offReason': '', 'parentid': '', 'preid': '', 'processid': '', 'productSn': '浙妆20160057', 'provinceCode': '', 'qfDate': '', 'qfManagerName': '浙江省食品药品监督管理局', 'qualityPerson': '王伟', 'rcManagerDepartName': '三门县市场监督管理局', 'rcManagerUser': '陈妮娜、王灵珠', 'startTime': '', 'xkCompleteDate': None, 'xkDate': '2021-08-22', 'xkDateStr': '2019-11-26', 'xkName': '陈书来', 'xkProject': '', 'xkRemark': '', 'xkType': '206'}, {'businessLicenseNumber': '91440101MA5CM1G52K', 'businessPerson': '胡敏', 'certStr': '一般液态单元（护发清洁类、护肤水类、染烫发类、啫喱类）；膏霜乳液单元（护肤清洁类、护发类、染烫发类）', 'cityCode': '', 'countyCode': '', 'creatUser': '', 'createTime': '', 'endTime': '', 'epsAddress': '广州市白云区江高镇塘荔路3号 （自主申报）', 'epsName': '广州市三荣化妆品有限公司', 'epsProductAddress': '广州市白云区江高镇塘荔路3号A1栋、B栋', 'id': '', 'isimport': 'Y', 'legalPerson': '陈  津', 'offDate': '', 'offReason': '', 'parentid': '', 'preid': '', 'processid': '', 'productSn': '粤妆20190261', 'provinceCode': '', 'qfDate': '', 'qfManagerName': '广东省药品监督管理局', 'qualityPerson': '陈朝晖', 'rcManagerDepartName': '白云区局江高市场监管所', 'rcManagerUser': '监管机构指定人员', 'startTime': '', 'xkCompleteDate': None, 'xkDate': '2024-11-25', 'xkDateStr': '2019-11-26', 'xkName': '严振', 'xkProject': '', 'xkRemark': '无', 'xkType': '201'}, {'businessLicenseNumber': '91440101MA59EU7581', 'businessPerson': '廖广光', 'certStr': '一般液态单元（护发清洁类、护肤水类、啫喱类）；膏霜乳液单元（护肤清洁类、护发类）', 'cityCode': '', 'countyCode': '', 'creatUser': '', 'createTime': '', 'endTime': '', 'epsAddress': '广州市白云区白云湖街夏茅向西大道十九社工业区自编一号五楼', 'epsName': '广州市欣俊颜化妆品有限公司', 'epsProductAddress': '广州市白云区白云湖街夏茅向西大道十九社工业区自编一号五楼', 'id': '', 'isimport': 'Y', 'legalPerson': '廖广光', 'offDate': '', 'offReason': '', 'parentid': '', 'preid': '', 'processid': '', 'productSn': '粤妆20161719', 'provinceCode': '', 'qfDate': '', 'qfManagerName': '广东省药品监督管理局', 'qualityPerson': '丁祥华', 'rcManagerDepartName': '白云区局白云湖市场监管所', 'rcManagerUser': '监管机构指定人员', 'startTime': '', 'xkCompleteDate': None, 'xkDate': '2021-12-25', 'xkDateStr': '2019-11-26', 'xkName': '严振', 'xkProject': '', 'xkRemark': '无', 'xkType': '206'}, {'businessLicenseNumber': '91440111761911773J', 'businessPerson': '张龙光', 'certStr': '一般液态单元（护发清洁类、护肤水类、啫喱类）；膏霜乳液单元（护肤清洁类、护发类）', 'cityCode': '', 'countyCode': '', 'creatUser': '', 'createTime': '', 'endTime': '', 'epsAddress': '广州市白云区均禾街石马村旺发大街自编25号', 'epsName': '广州甲美生物科技有限公司', 'epsProductAddress': '广州市白云区均禾街石马村旺发大街自编25号', 'id': '', 'isimport': 'Y', 'legalPerson': '张龙光', 'offDate': '', 'offReason': '', 'parentid': '', 'preid': '', 'processid': '', 'productSn': '粤妆20161580', 'provinceCode': '', 'qfDate': '', 'qfManagerName': '广东省药品监督管理局', 'qualityPerson': '王金材', 'rcManagerDepartName': '白云区局均禾市场监管所', 'rcManagerUser': '监管机构指定人员', 'startTime': '', 'xkCompleteDate': None, 'xkDate': '2021-12-13', 'xkDateStr': '2019-11-26', 'xkName': '严振', 'xkProject': '', 'xkRemark': '无', 'xkType': '206'}, {'businessLicenseNumber': '91440111585697332C', 'businessPerson': '陈坚', 'certStr': '一般液态单元（护发清洁类、护肤水类、染烫发类、啫喱类）；膏霜乳液单元（护肤清洁类、护发类、染烫发类）', 'cityCode': '', 'countyCode': '', 'creatUser': '', 'createTime': '', 'endTime': '', 'epsAddress': '广州市白云区江高镇神山雄郭西路128号3栋101房、201房（自主申报）', 'epsName': '广州卡丝蓝化妆品有限公司', 'epsProductAddress': '广州市白云区江高镇神山雄郭西路128号3栋101房、201房', 'id': '', 'isimport': 'Y', 'legalPerson': '申明辉', 'offDate': '', 'offReason': '', 'parentid': '', 'preid': '', 'processid': '', 'productSn': '粤妆20161239', 'provinceCode': '', 'qfDate': '', 'qfManagerName': '广东省药品监督管理局', 'qualityPerson': '彭孝利', 'rcManagerDepartName': '白云区局江高市场监管所', 'rcManagerUser': '监管机构指定人员', 'startTime': '', 'xkCompleteDate': None, 'xkDate': '2024-11-25', 'xkDateStr': '2019-11-26', 'xkName': '严振', 'xkProject': '', 'xkRemark': '无', 'xkType': '206'}, {'businessLicenseNumber': '91440111745972816M', 'businessPerson': '刘成伟', 'certStr': '一般液态单元（护发清洁类、护肤水类、啫喱类）；膏霜乳液单元（护肤清洁类、护发类）；粉单元（散粉类、块状粉类）', 'cityCode': '', 'countyCode': '', 'creatUser': '', 'createTime': '', 'endTime': '', 'epsAddress': '广州市白云区均禾街罗岗工业区企业路23号', 'epsName': '广州市绿色春天化妆品科技研发有限公司', 'epsProductAddress': '广州市白云区均禾街罗岗工业区企业路23号', 'id': '', 'isimport': 'Y', 'legalPerson': '刘成伟', 'offDate': '', 'offReason': '', 'parentid': '', 'preid': '', 'processid': '', 'productSn': '粤妆20160777', 'provinceCode': '', 'qfDate': '', 'qfManagerName': '广东省药品监督管理局', 'qualityPerson': '罗松南', 'rcManagerDepartName': '白云区局均禾市场监管所', 'rcManagerUser': '监管机构指定人员', 'startTime': '', 'xkCompleteDate': None, 'xkDate': '2021-09-26', 'xkDateStr': '2019-11-26', 'xkName': '严振', 'xkProject': '', 'xkRemark': '无', 'xkType': '206'}]\n"
     ]
    }
   ],
   "source": [
    "import requests\n",
    "import json\n",
    "ids = []\n",
    "detailed_data_list = []\n",
    "url = 'http://125.35.6.84:81/xk/itownet/portalAction.do?method=getXkzsList'\n",
    "headers = {\n",
    "            'User-Agent':'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.108 Safari/537.36'\n",
    "        }\n",
    "data = {\n",
    "    'on': 'true',\n",
    "    'page': '1',\n",
    "    'pageSize': '15',\n",
    "    'productName': '',\n",
    "    'conditionType': '1',\n",
    "    'applyname': '',\n",
    "    'applysn': '',\n",
    "}\n",
    "response = requests.post(url=url, headers=headers, data=data)\n",
    "response.encoding = 'utf-8'\n",
    "response_data_ids = response.json()\n",
    "# print([response_data_ids])\n",
    "for i in response_data_ids['list']:\n",
    "    ids.append(i['ID'])\n",
    "\n",
    "detailed_url = 'http://125.35.6.84:81/xk/itownet/portalAction.do?method=getXkzsById'\n",
    "for i in ids:\n",
    "    data_d = {\n",
    "        'id': i\n",
    "    }\n",
    "    response_d = requests.post(url=detailed_url, headers=headers, data=data_d)\n",
    "    response_d.encoding = 'utf-8'\n",
    "    response_d_data = response_d.json()\n",
    "    detailed_data_list.append(response_d_data)\n",
    "# print(detailed_data_list)\n",
    "with open('detailed_data.html', 'w', encoding='utf-8')as f:\n",
    "    f.write(json.dumps(detailed_data_list))\n",
    "print('成功！')\n",
    "with open('detailed_data.html', 'r', encoding='utf-8')as f:\n",
    "    print(json.loads(f.read()))"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
